var xmlhttp

if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
else
 xmlhttp=false

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}


/**
 *
 * @access public
 * @return void 
 **/
function ajax_sendRequest(params, idLayer = -1, reqFunction = null){
	if(idLayer != -1) { // It should be great to use a template for waiting instead of preconfigured html
		var element = document.getElementById(idLayer);
		if(element != 'undefined')
			element.innerHTML = '<small>Please wait while your request is treat</small>';	
	}	
	
	xmlhttp.open('post', 'ajax.php?'+params);
	if(reqFunction == null)
		xmlhttp.onreadystatechange = ajax_handleResponse;
	else
		xmlhttp.onreadystatechange = ajax_handleResponse; // need to use content of var reqFunction
		
	xmlhttp.send(null);
}

/**
 *
 * @access public
 * @return void 
 **/
function ajax_handleResponse(){
	if(xmlhttp.readyState == 4){
		 if (xmlhttp.status == 200){

        var response = xmlhttp.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {

            update = response.split('|');
			var tag = 'star_long'+update[4] ;
		    document.getElementById(tag).style.display = 'none' ;
		  	tag = 'note' + update[4] ;
            changeText(tag, update[1]);
            tag = 'nb_votant' + update[4] ;
            changeText(tag, update[3]);
			tag = 'on' + update[4] ;
            document.getElementById(tag).style.display = 'inline';
            tag = 'actualNote' + update[4] ;
            document.getElementById(tag).style.display = 'inline';


        } else {
          alert('Un probleme est survenue : '+response) ;
        }

		 } else {
		   	alert('Technologie AJAX indisponible, contactez l\'administrateur du site Internet') ;
		 }
    }
}